09. Exercise: Connect Firebase and the Squawker App

Connect Firebase and Android

In this exercise, you'll be doing two things. First, creating a new Firebase project, and second, configuring Squawker to work with FCM.

Exercise Code

Exercise: TFCM.01-Exercise-AddGradleDependencies

The Automated Way

There are two ways to complete this exercise. I suggest the "manual way" (which is described below) so that you clearly know what you are changing. That said, if you have Android Studio version 2.2 or above and would like to do a more automated process, you can follow the instructions here. Note that if you follow the automated directions, you only need to do the first two steps: "Connect your app to Firebase" and "Add FCM to your app". You should not do step 3, which is "Access the Device Registration token".

Otherwise, let's manually configure Firebase! Creating a new project is very easy, so let's do that first.

Create a new Firebase Project

Step 1 Go to the Firebase Console and click on Create a new Project.

Step 2 Name your project Squawker

And that's it! You've created a Firebase project for Squawker. Now it's time to create a Firebase "app" for that project and attach it to your Squakwer app.

Connect the Squawker Android App to the Server

Step 1 Select Add Firebase to your Android App

Step 2 Enter the Squawker package into the dialog. It is android.example.com.squawker. You don't need a SHA key because we are not using Firebase features which require it. You also do not need the app nickname, though feel free to add one if you'd like.

Step 3 Follow the instructions to download the google-service.json config file and save it in Squawker's app directory. This configuration file is what tells Squawker what Firebase server instance to connect to online. It is specific to the Firebase "app" you just created. If you ever accidentally delete the google-service.json file, you can redownload it, by going to the app Settings.

Step 4 Now you'll add the Firebase SDK. Follow the instructions to add the correct gradle dependencies. The instructions will appear in a dialog, they can also be found here.

Step 5 You need to also add the SDK specifically for FCM. In your app/build.gradle file, add the following library:

com.google.firebase:firebase-messaging:10.2.0

Task Description:

Okay, now it's your turn. Follow the steps to complete this coding exercise.

Task List:

Task Feedback:

Excellent work!

Solution: [TFCM.01-Solution-AddGradleDependencies][Diff]